package com.itfreer.content.task.workSitutation;

import com.itfreer.core.config.ConfigManager;
import com.itfreer.core.http.HttpUtils;
import com.itfreer.core.volley.HeaderUtils;
import com.itfreer.core.volley.RequestManager;
import com.itfreer.core.volley.callback.DataCallback;

import org.json.JSONArray;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WorkSitutationService {

    public static final WorkSitutationService instance = new WorkSitutationService();

    public List<WorkSitutationVO> getDataSituationByState(WorkSitutationDTO work) {
        try {
            if (work == null) {
                work = new WorkSitutationDTO();
            }
            if(ConfigManager.getUser() != null) {
                work.setOwerid(ConfigManager.getUser().getUserId());// 默认查询当前用户数据
            }
            work.setState(2);// 默认根据月份来查询
            String url = ConfigManager.getHttpUrl();
            if(url.endsWith("/")) {
                url += "locuswork/getDataSituationByState";
            } else {
                url += "/locuswork/getDataSituationByState";
            }

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("owerid",work.getOwerid());
            jsonObject.put("state",work.getState());
            jsonObject.put("startTime",work.getStartTime().getTime());
            jsonObject.put("endTime",work.getEndTime().getTime());
            String json = jsonObject.toString();
            List<WorkSitutationVO> result = HttpUtils.postList(url, json, WorkSitutationVO.class);
            return result;
        } catch (Exception ex) {
            System.out.println("错误");
            return new ArrayList<WorkSitutationVO>();
//            throw new RuntimeException(ex);
        }
    }
}
